package com.twu.biblioteca;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by aswathik on 6/17/14.
 */
public class Menu {

    Library library;
    private  Map<Integer, MenuItem> menuItems = new HashMap<Integer, MenuItem>();

    Menu(List<MenuItem> menuItemList) {
        createMappingOfMenuItems(menuItemList);
    }

    private void createMappingOfMenuItems(List<MenuItem> menuItemList) {
        for ( int i = 0; i < menuItemList.size(); i++) {
            menuItems.put(i+1, menuItemList.get(i));
        }
    }

    protected void displayMenu ( UserInterface userInterface) {
        String menuToDisplay = new String();
        for (Integer integer : menuItems.keySet()) {
            menuToDisplay = integer +". "+(menuItems.get(integer).getMenuString()+"\n");
            userInterface.displayResultString(menuToDisplay);
        }
    }

    protected MenuItem getMenuItemForOption (int option)  {
        if ( menuItems.containsKey(option)) {
            return menuItems.get(option);
        }
        return null;
    }
}
